package com.ztjc.day01_sendsms;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;

import java.util.ArrayList;

/**
 * 短信发送器
 * 思路：
 *      1.编写界面
 *      2.编写逻辑代码
 *      3.添加权限
 */
public class MainActivity extends Activity {

    // 声明控件
    private EditText et_phone;
    private EditText et_sms_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 实例化控件
        et_phone = (EditText) findViewById(R.id.et_phone);
        et_sms_content = (EditText) findViewById(R.id.et_sms_content);
    }

    public void send(View view) {
        // 获取电话号码和短信内容
        String phoneNum = et_phone.getText().toString();
        String smsContent = et_sms_content.getText().toString();

        // 获取短信管理器
        SmsManager smsManager = SmsManager.getDefault();
        // 切割短信
        ArrayList<String> strings = smsManager.divideMessage(smsContent);
        // 发送短信
        smsManager.sendMultipartTextMessage(phoneNum, null, strings, null, null);
    }
}
